<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>

<script>
    function initList() {
        $('#tt').tree({
            url : "<c:url value='/dom/findDom.do'/>",
            //checkbox : true,
            loadFilter : function(data) {
                if (data.d) {
                    return data.d;
                } else {
                    return data;
                }
            }/*,
             onClick : function(node) {
                if (node.link == 1) {
                    downDom(node.id);
                }
            } */
        });

    }

    $(document).ready(function() {
        initList();
    });

    function uploadDom() {
        
        var node = $('#tt').tree('getSelected');
        if (node && node.folder == "1"){
            $('#domForm').form('submit', {
                url : '<c:url value='/dom/uploadDom.do'/>' + "?parentDomId=" + node.id, //查询提交路径
                onSubmit : function()//提交按钮相应函数
                {
                    return $('#domForm').form('validate');
                },
                success : function(data) {
                    data = eval("(" + data + ")");
                    if (data.success) {
                        $.messager.alert("提示", "创建成功！", 'info', function() {
                            $('#tt').tree('reload',node.target);
                        });
                    } else {
                    	if(data.msg =="msg001"){
                            $.messager.alert("提示", "系统已有同名文件，请换个名称。", 'warning');
                        }else{
                            $.messager.alert("提示", data.msg, 'warning');
                        }
                    }
                },
                error : function() {
                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                    return;
                }
            });
        }else{
            $.messager.alert("错误", "请您选取一个文件夹", 'error');
            return;
        }
    }
    
    function deleteDom() {
        var node = $('#tt').tree('getSelected');
        if (node){
        	$('#domDeleteForm').form('submit', {
                url : '<c:url value='/dom/deleteDom.do'/>' + "?domId=" + node.id, //查询提交路径
                onSubmit : function()//提交按钮相应函数
                {
                    return $('#domDeleteForm').form('validate');
                },
                success : function(data) {
                    data = eval("(" + data + ")");
                    if (data.success) {
                        $.messager.alert("提示", "删除成功！", 'info', function() {
                            var nodeParent = $('#tt').tree('getParent',node.target);
                            $('#tt').tree('reload',nodeParent.target);
                        });
                    } else {
                    	if(data.msg =="msg002"){
                            $.messager.alert("提示", "根目录不能删除。", 'warning');
                        }else{
                            $.messager.alert("提示", data.msg, 'warning');
                        }
                    }
                },
                error : function() {
                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                    return;
                }
            });
        }else{
            $.messager.alert("错误", "请您选取一个文件", 'error');
            return;
        }    
    }

    function createFolderCheck() {
    	if( $('#domText').val()==''){
    		$.messager.alert("错误", "请填写文件名。", 'error');
            return;
    	}
    	
    	var node = $('#tt').tree('getSelected');
        if (node && node.folder == "1"){
            createFolder(node);
        }else{
        	$.messager.alert("错误", "请您选取一个文件夹", 'error');
            return;
        }
    }
    
    function createFolder(node) {
        $('#domFolderForm').form('submit', {
            url : '<c:url value='/dom/createFolder.do'/>' + "?parentDomId=" + node.id, //查询提交路径
            onSubmit : function()//提交按钮相应函数
            {
                return $('#domFolderForm').form('validate');
            },
            success : function(data) {
                data = eval("(" + data + ")");
                if (data.success) {
                    $.messager.alert("提示", "创建成功！", 'info', function() {
                    	$('#tt').tree('reload',node.target);
                    });
                } else {
                    if(data.msg =="msg001"){
                        $.messager.alert("提示", "系统已有同名文件，请换个名称。", 'warning');
                    }else{
                        $.messager.alert("提示", data.msg, 'warning');
                    }
                }
            },
            error : function() {
                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                return;
            }
        });
    }
</script>


</head>
<body>
    <table>
        <tr>
            <td colspan="2"><div
                    style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
                    class="easyui-panel" title="操作" iconCls="icon-add"
                    collapsible="true" minimizable="false" maximizable="false"
                    closable="false">
                    <form id="domFolderForm" name="domFolderForm" method="post"
                        enctype="multipart/form-data" action="userlist.txt"
                        onsubmit="return searchDGData(this.id,'listDisplay');">
                        <div>
                            <table cellpadding="5">
                                <tr>
                                    <td>文件夹名称</td>
                                    <td><input class="easyui-validatebox" id="domText" editable="true" name="domText" ></input></td>
                                    <td><input type="button" onclick="createFolderCheck()" value="创建文件夹"></td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </div></td>
        </tr>
        <tr>
            <td><div
                    style="height: auto; width: 590px; background: #fafafa; padding: 5px;"
                    class="easyui-panel" title="上传文件" iconCls="icon-add"
                    collapsible="true" minimizable="false" maximizable="false"
                    closable="false">
                    <form id="domForm" name="domForm" method="post"
                        enctype="multipart/form-data" action="userlist.txt"
                        onsubmit="return searchDGData(this.id,'listDisplay');">
                        <div>
                            <table cellpadding="5">
                                <tr>
                                    <td>文件本地路径</td>
                                    <td><input class="easyui-filebox" name="file"
                                        required="true"></input></td>
                                    <td><input type="button" onclick="uploadDom()" value="上传"></td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </div></td>
                <td><div
                    style="height: auto; width: 585px; background: #fafafa; padding: 5px;"
                    class="easyui-panel" title="删除文件" iconCls="icon-add"
                    collapsible="true" minimizable="false" maximizable="false"
                    closable="false">
                    <form id="domDeleteForm" name="domDeleteForm" method="post"
                        enctype="multipart/form-data" action="userlist.txt"
                        onsubmit="return searchDGData(this.id,'listDisplay');">
                        <div>
                            <table cellpadding="5">
                                <tr>
                                    <td><input type="button" onclick="deleteDom()" value="删除"></td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </div></td>
        </tr>
        
        <tr>
            <td>
                <form id="excelForm" name="excelForm" method="post"
                    enctype="multipart/form-data" action="userlist.txt"
                    onsubmit="return searchDGData(this.id,'listDisplay');"></form>
            </td>
        </tr>

        <tt>
            <td colspan="2">
                <div
                    style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
                    class="easyui-panel" title="文件路径" iconCls="icon-add"
                    collapsible="true" minimizable="false" maximizable="false"
                    closable="false">
                    <table>
                        <tr>
                            <td>
                                <ul id="tt" class="easyui-tree"></ul>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tt>
    </table>

</body>
</html>